<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <style>
        *{
            padding: 0;
            margin: 0;
        }
        ul{
            width: 80px;
            border: 2px solid rgb(117, 21, 21);
            display: none;
            position: fixed;
            height: 250px;
        }
        li{
            list-style: none;
            height: 50px;
            line-height: 50px;
            text-align: center;
            border-bottom: 2px solid rgb(117, 21, 21);
        }
        li:last-child{
            border: none;
        }
        li:hover{
            background: yellow;
        }
    </style>
</head>
<body>
    <ul>
        <li>菜单</li>
        <li>保存</li>
        <li>刷新</li>
        <li>复制</li>
        <li>粘贴</li>
    </ul>
</body>
</html>
<script>
    const ul = document.querySelector('ul')
    document.addEventListener('contextmenu',function(e){
        e.preventDefault()
        console.log(e);
        ul.style.top = e.clientY + 'px'
        ul.style.left = e.clientX + 'px'
        ul.style.display = 'block'
    })
    document.addEventListener('click',function(e){
        ul.style.display = 'none'
    })
</script>